/*
 * @Author: dengzhijun 1726768643@qq.com
 * @Date: 2025-01-23 09:35:08
 * @LastEditors: dengzhijun 1726768643@qq.com
 * @LastEditTime: 2025-01-23 10:57:17
 * @FilePath: /Tools/Tool/include/DataTime.h
 * @Description:
 * Copyright (c) 2025 by ${dengzhijun} email: ${1726768643@qq.com}, All Rights Reserved.
 */

#ifndef TOOLS_TOOL_DataTime_H
#define TOOLS_TOOL_DataTime_H

#include <chrono>
#include <string>
#include "Global.h"

namespace Tool
{
class ExportAPI DataTime
{
public:
    using time_point = std::chrono::system_clock::time_point;
    using duration = std::chrono::system_clock::duration;
    DataTime();

    // explicit 关键字表示这个构造函数是显式的，不能用于隐式类型转换。
    explicit DataTime(time_point tp);
    void SetTime(const time_point &tp);
    time_point GetTime() const;
    static DataTime CurrentDateTime();
    static DataTime Now();
    int64_t ToSecsSinceEpoch() const;
    int64_t ToMSecsSinceEpoch() const;
    static DataTime FromSecsSinceEpoch(int64_t secs);
    static DataTime FromMsecsSinceEpoch(int64_t msecs);

    static int64_t CurrentSeconds();        //当前时间秒
    static int64_t CurrentMilliseconds();   //当前时间毫秒 时间戳

    // %Y:%m-%d %H:%M:%S.%ms
    std::string ToString(const std::string &fmt = "%Y-%m-%d %H:%M:%S") const;
    friend bool operator==(const DataTime& lhs, const DataTime& rhs);
    friend bool operator!=(const DataTime& lhs, const DataTime& rhs);
    friend bool operator<(const DataTime& lhs, const DataTime& rhs);
    friend bool operator<=(const DataTime& lhs, const DataTime& rhs);
    friend bool operator>(const DataTime& lhs, const DataTime& rhs);
    friend bool operator>=(const DataTime& lhs, const DataTime& rhs);
private:
    time_point m_timePoint;
};
}
#endif
